/*   1:    */ package org.jetbrains.jsonProtocol;
/*   2:    */ 
/*   3:    */

import com.google.gson.stream.JsonToken;
import com.intellij.util.ArrayUtilRt;
import gnu.trove.TDoubleArrayList;
import gnu.trove.THashMap;
import gnu.trove.TIntArrayList;
import gnu.trove.TLongArrayList;
import org.jetbrains.io.JsonReaderEx;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */ 
/*  15:    */ public final class JsonReaders
/*  16:    */ {
/*  17:    */   private static void a(JsonReaderEx paramJsonReaderEx, String paramString)
/*  18:    */   {
/*  19: 21 */     if (paramJsonReaderEx.peek() == JsonToken.NULL) {
/*  20: 22 */       throw new RuntimeException("Field is not nullable" + (paramString == null ? "" : new StringBuilder().append(": ").append(paramString).toString()));
/*  21:    */     }
/*  22:    */   }
/*  23:    */   
/*  24:    */   public static String readString(JsonReaderEx paramJsonReaderEx, String paramString)
/*  25:    */   {
/*  26: 27 */     a(paramJsonReaderEx, paramString);
/*  27: 28 */     return paramJsonReaderEx.nextString();
/*  28:    */   }
/*  29:    */   
/*  30:    */   public static String readRawString(JsonReaderEx paramJsonReaderEx)
/*  31:    */   {
/*  32: 32 */     return paramJsonReaderEx.nextString(true);
/*  33:    */   }
/*  34:    */   
/*  35:    */   public static Object readRawStringOrMap(JsonReaderEx paramJsonReaderEx)
/*  36:    */   {
/*  37: 36 */     if (paramJsonReaderEx.peek() == JsonToken.BEGIN_OBJECT) {
/*  38: 37 */       return readMap(paramJsonReaderEx, null);
/*  39:    */     }
/*  40: 40 */     return paramJsonReaderEx.nextString(true);
/*  41:    */   }
/*  42:    */   
/*  43:    */   public static String readNullableString(JsonReaderEx paramJsonReaderEx)
/*  44:    */   {
/*  45: 45 */     if (paramJsonReaderEx.peek() == JsonToken.NULL)
/*  46:    */     {
/*  47: 46 */       paramJsonReaderEx.skipValue();
/*  48: 47 */       return null;
/*  49:    */     }
/*  50: 49 */     return paramJsonReaderEx.nextString();
/*  51:    */   }
/*  52:    */   
/*  53:    */   public static boolean readBoolean(JsonReaderEx paramJsonReaderEx, String paramString)
/*  54:    */   {
/*  55: 53 */     a(paramJsonReaderEx, paramString);
/*  56: 54 */     return paramJsonReaderEx.nextBoolean();
/*  57:    */   }
/*  58:    */   
/*  59:    */   public static boolean readNullableBoolean(JsonReaderEx paramJsonReaderEx)
/*  60:    */   {
/*  61: 58 */     if (paramJsonReaderEx.peek() == JsonToken.NULL)
/*  62:    */     {
/*  63: 59 */       paramJsonReaderEx.skipValue();
/*  64: 60 */       return false;
/*  65:    */     }
/*  66: 62 */     return paramJsonReaderEx.nextBoolean();
/*  67:    */   }
/*  68:    */   
/*  69:    */   public static int readInt(JsonReaderEx paramJsonReaderEx, String paramString)
/*  70:    */   {
/*  71: 66 */     a(paramJsonReaderEx, paramString);
/*  72: 67 */     return paramJsonReaderEx.nextInt();
/*  73:    */   }
/*  74:    */   
/*  75:    */   public static int readNullableInt(JsonReaderEx paramJsonReaderEx)
/*  76:    */   {
/*  77: 71 */     if (paramJsonReaderEx.peek() == JsonToken.NULL)
/*  78:    */     {
/*  79: 72 */       paramJsonReaderEx.skipValue();
/*  80: 73 */       return -1;
/*  81:    */     }
/*  82: 75 */     return paramJsonReaderEx.nextInt();
/*  83:    */   }
/*  84:    */   
/*  85:    */   public static long readLong(JsonReaderEx paramJsonReaderEx, String paramString)
/*  86:    */   {
/*  87: 79 */     a(paramJsonReaderEx, paramString);
/*  88: 80 */     return paramJsonReaderEx.nextLong();
/*  89:    */   }
/*  90:    */   
/*  91:    */   public static double readDouble(JsonReaderEx paramJsonReaderEx, String paramString)
/*  92:    */   {
/*  93: 84 */     a(paramJsonReaderEx, paramString);
/*  94: 85 */     return paramJsonReaderEx.nextDouble();
/*  95:    */   }
/*  96:    */   
/*  97:    */   public static long readNullableLong(JsonReaderEx paramJsonReaderEx)
/*  98:    */   {
/*  99: 89 */     if (paramJsonReaderEx.peek() == JsonToken.NULL)
/* 100:    */     {
/* 101: 90 */       paramJsonReaderEx.skipValue();
/* 102: 91 */       return -1L;
/* 103:    */     }
/* 104: 93 */     return paramJsonReaderEx.nextLong();
/* 105:    */   }
/* 106:    */   
/* 107:    */   public static <T extends Enum<T>> T readEnum(JsonReaderEx paramJsonReaderEx, String paramString, Class<T> paramClass)
/* 108:    */   {
/* 109: 97 */     a(paramJsonReaderEx, paramString);
/* 110:    */     try
/* 111:    */     {
/* 112: 99 */       return Enum.valueOf(paramClass, a(paramJsonReaderEx));
/* 113:    */     }
/* 114:    */     catch (IllegalArgumentException localIllegalArgumentException) {}
/* 115:102 */     return Enum.valueOf(paramClass, "NO_ENUM_CONST");
/* 116:    */   }
/* 117:    */   
/* 118:    */   public static String convertRawEnumName(String paramString)
/* 119:    */   {
/* 120:107 */     StringBuilder localStringBuilder = new StringBuilder(paramString.length() + 4);
/* 121:108 */     int i = 0;
/* 122:109 */     for (int j = 0; j < paramString.length(); j++)
/* 123:    */     {
/* 124:110 */       char c = paramString.charAt(j);
/* 125:111 */       if (c == '-')
/* 126:    */       {
/* 127:112 */         localStringBuilder.append('_');
/* 128:    */       }
/* 129:116 */       else if (Character.isUpperCase(c))
/* 130:    */       {
/* 131:118 */         if ((i != 0) || ((j + 1 < paramString.length()) && (Character.isLowerCase(paramString.charAt(j + 1))))) {
/* 132:119 */           localStringBuilder.append('_');
/* 133:    */         }
/* 134:121 */         localStringBuilder.append(c);
/* 135:    */       }
/* 136:    */       else
/* 137:    */       {
/* 138:124 */         localStringBuilder.append(Character.toUpperCase(c));
/* 139:125 */         i = 1;
/* 140:    */       }
/* 141:    */     }
/* 142:128 */     return localStringBuilder.toString();
/* 143:    */   }
/* 144:    */   
/* 145:    */   private static String a(JsonReaderEx paramJsonReaderEx)
/* 146:    */   {
/* 147:132 */     return convertRawEnumName(paramJsonReaderEx.nextString());
/* 148:    */   }
/* 149:    */   
/* 150:    */   public static <T extends Enum<T>> T readNullableEnum(JsonReaderEx paramJsonReaderEx, Class<T> paramClass)
/* 151:    */   {
/* 152:136 */     if (paramJsonReaderEx.peek() == JsonToken.NULL)
/* 153:    */     {
/* 154:137 */       paramJsonReaderEx.skipValue();
/* 155:138 */       return null;
/* 156:    */     }
/* 157:140 */     return Enum.valueOf(paramClass, a(paramJsonReaderEx));
/* 158:    */   }
/* 159:    */   
/* 160:    */   public static <T> List<T> readObjectArray(JsonReaderEx paramJsonReaderEx, String paramString, ObjectFactory<T> paramObjectFactory, boolean paramBoolean)
/* 161:    */   {
/* 162:144 */     if (paramJsonReaderEx.peek() == JsonToken.NULL)
/* 163:    */     {
/* 164:145 */       if (paramBoolean)
/* 165:    */       {
/* 166:146 */         paramJsonReaderEx.skipValue();
/* 167:147 */         return null;
/* 168:    */       }
/* 169:150 */       a(paramJsonReaderEx, paramString);
/* 170:    */     }
/* 171:154 */     paramJsonReaderEx.beginArray();
/* 172:155 */     if (!paramJsonReaderEx.hasNext())
/* 173:    */     {
/* 174:156 */       paramJsonReaderEx.endArray();
/* 175:157 */       if (paramBoolean) {
/* 176:158 */         return null;
/* 177:    */       }
/* 178:161 */       return Collections.emptyList();
/* 179:    */     }
/* 180:165 */     ArrayList localArrayList = new ArrayList();
/* 181:    */     do
/* 182:    */     {
/* 183:167 */       localArrayList.add(paramObjectFactory.read(paramJsonReaderEx));
/* 184:169 */     } while (paramJsonReaderEx.hasNext());
/* 185:170 */     paramJsonReaderEx.endArray();
/* 186:171 */     return localArrayList;
/* 187:    */   }
/* 188:    */   
/* 189:    */   public static Map<?, ?> readMap(JsonReaderEx paramJsonReaderEx, String paramString)
/* 190:    */   {
/* 191:175 */     a(paramJsonReaderEx, paramString);
/* 192:176 */     paramJsonReaderEx.beginObject();
/* 193:177 */     if (!paramJsonReaderEx.hasNext())
/* 194:    */     {
/* 195:178 */       paramJsonReaderEx.endObject();
/* 196:179 */       return Collections.emptyMap();
/* 197:    */     }
/* 198:181 */     return nextObject(paramJsonReaderEx);
/* 199:    */   }
/* 200:    */   
/* 201:    */   public static Object read(JsonReaderEx paramJsonReaderEx)
/* 202:    */   {
/* 203:185 */     switch (1.$SwitchMap$com$google$gson$stream$JsonToken[paramJsonReaderEx.peek().ordinal()])
/* 204:    */     {
/* 205:    */     case 1: 
/* 206:187 */       return nextList(paramJsonReaderEx);
/* 207:    */     case 2: 
/* 208:190 */       paramJsonReaderEx.beginObject();
/* 209:191 */       return nextObject(paramJsonReaderEx);
/* 210:    */     case 3: 
/* 211:194 */       return paramJsonReaderEx.nextString();
/* 212:    */     case 4: 
/* 213:197 */       return Double.valueOf(paramJsonReaderEx.nextDouble());
/* 214:    */     case 5: 
/* 215:200 */       return Boolean.valueOf(paramJsonReaderEx.nextBoolean());
/* 216:    */     case 6: 
/* 217:203 */       paramJsonReaderEx.nextNull();
/* 218:204 */       return null;
/* 219:    */     }
/* 220:206 */     throw new IllegalStateException();
/* 221:    */   }
/* 222:    */   
/* 223:    */   public static Map<String, Object> nextObject(JsonReaderEx paramJsonReaderEx)
/* 224:    */   {
/* 225:211 */     THashMap localTHashMap = new THashMap();
/* 226:212 */     while (paramJsonReaderEx.hasNext()) {
/* 227:213 */       localTHashMap.put(paramJsonReaderEx.nextName(), read(paramJsonReaderEx));
/* 228:    */     }
/* 229:215 */     paramJsonReaderEx.endObject();
/* 230:216 */     return localTHashMap;
/* 231:    */   }
/* 232:    */   
/* 233:    */   public static <T> List<T> nextList(JsonReaderEx paramJsonReaderEx)
/* 234:    */   {
/* 235:220 */     paramJsonReaderEx.beginArray();
/* 236:221 */     if (!paramJsonReaderEx.hasNext())
/* 237:    */     {
/* 238:222 */       paramJsonReaderEx.endArray();
/* 239:223 */       return Collections.emptyList();
/* 240:    */     }
/* 241:226 */     ArrayList localArrayList = new ArrayList();
/* 242:    */     do
/* 243:    */     {
/* 244:229 */       localArrayList.add(read(paramJsonReaderEx));
/* 245:231 */     } while (paramJsonReaderEx.hasNext());
/* 246:232 */     paramJsonReaderEx.endArray();
/* 247:233 */     return localArrayList;
/* 248:    */   }
/* 249:    */   
/* 250:    */   public static long[] readLongArray(JsonReaderEx paramJsonReaderEx)
/* 251:    */   {
/* 252:237 */     a(paramJsonReaderEx, null);
/* 253:238 */     paramJsonReaderEx.beginArray();
/* 254:239 */     if (!paramJsonReaderEx.hasNext())
/* 255:    */     {
/* 256:240 */       paramJsonReaderEx.endArray();
/* 257:241 */       return ArrayUtilRt.EMPTY_LONG_ARRAY;
/* 258:    */     }
/* 259:244 */     TLongArrayList localTLongArrayList = new TLongArrayList();
/* 260:    */     do
/* 261:    */     {
/* 262:246 */       localTLongArrayList.add(paramJsonReaderEx.nextLong());
/* 263:248 */     } while (paramJsonReaderEx.hasNext());
/* 264:249 */     paramJsonReaderEx.endArray();
/* 265:250 */     return localTLongArrayList.toNativeArray();
/* 266:    */   }
/* 267:    */   
/* 268:    */   public static double[] readDoubleArray(JsonReaderEx paramJsonReaderEx)
/* 269:    */   {
/* 270:254 */     a(paramJsonReaderEx, null);
/* 271:255 */     paramJsonReaderEx.beginArray();
/* 272:256 */     if (!paramJsonReaderEx.hasNext())
/* 273:    */     {
/* 274:257 */       paramJsonReaderEx.endArray();
/* 275:258 */       return new double[] { 0.0D };
/* 276:    */     }
/* 277:261 */     TDoubleArrayList localTDoubleArrayList = new TDoubleArrayList();
/* 278:    */     do
/* 279:    */     {
/* 280:263 */       localTDoubleArrayList.add(paramJsonReaderEx.nextDouble());
/* 281:265 */     } while (paramJsonReaderEx.hasNext());
/* 282:266 */     paramJsonReaderEx.endArray();
/* 283:267 */     return localTDoubleArrayList.toNativeArray();
/* 284:    */   }
/* 285:    */   
/* 286:    */   public static int[] readIntArray(JsonReaderEx paramJsonReaderEx)
/* 287:    */   {
/* 288:271 */     a(paramJsonReaderEx, null);
/* 289:272 */     paramJsonReaderEx.beginArray();
/* 290:273 */     if (!paramJsonReaderEx.hasNext())
/* 291:    */     {
/* 292:274 */       paramJsonReaderEx.endArray();
/* 293:275 */       return ArrayUtilRt.EMPTY_INT_ARRAY;
/* 294:    */     }
/* 295:278 */     TIntArrayList localTIntArrayList = new TIntArrayList();
/* 296:    */     do
/* 297:    */     {
/* 298:280 */       localTIntArrayList.add(paramJsonReaderEx.nextInt());
/* 299:282 */     } while (paramJsonReaderEx.hasNext());
/* 300:283 */     paramJsonReaderEx.endArray();
/* 301:284 */     return localTIntArrayList.toNativeArray();
/* 302:    */   }
/* 303:    */   
/* 304:    */   public static List<StringIntPair> readIntStringPairs(JsonReaderEx paramJsonReaderEx)
/* 305:    */   {
/* 306:288 */     a(paramJsonReaderEx, null);
/* 307:289 */     paramJsonReaderEx.beginArray();
/* 308:290 */     if (!paramJsonReaderEx.hasNext())
/* 309:    */     {
/* 310:291 */       paramJsonReaderEx.endArray();
/* 311:292 */       return Collections.emptyList();
/* 312:    */     }
/* 313:295 */     ArrayList localArrayList = new ArrayList();
/* 314:    */     do
/* 315:    */     {
/* 316:297 */       paramJsonReaderEx.beginArray();
/* 317:298 */       localArrayList.add(new StringIntPair(paramJsonReaderEx.nextInt(), paramJsonReaderEx.nextString()));
/* 318:299 */       paramJsonReaderEx.endArray();
/* 319:301 */     } while (paramJsonReaderEx.hasNext());
/* 320:302 */     paramJsonReaderEx.endArray();
/* 321:303 */     return localArrayList;
/* 322:    */   }
/* 323:    */   
/* 324:    */   public static JsonReaderEx createReader(CharSequence paramCharSequence)
/* 325:    */   {
/* 326:307 */     return new JsonReaderEx(paramCharSequence);
/* 327:    */   }
/* 328:    */   
/* 329:    */   public static boolean findBooleanField(String paramString, JsonReaderEx paramJsonReaderEx)
/* 330:    */   {
/* 331:311 */     paramJsonReaderEx.beginObject();
/* 332:312 */     while (paramJsonReaderEx.hasNext())
/* 333:    */     {
/* 334:313 */       if (paramJsonReaderEx.nextName().equals(paramString)) {
/* 335:314 */         return paramJsonReaderEx.nextBoolean();
/* 336:    */       }
/* 337:317 */       paramJsonReaderEx.skipValue();
/* 338:    */     }
/* 339:320 */     return false;
/* 340:    */   }
/* 341:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.jetbrains.jsonProtocol.JsonReaders

 * JD-Core Version:    0.7.0.1

 */